/**
 * 
 */
$(function(){
    $(document).keyup(function (e) {
        if(e.which==13){
            $('#selectBtnEnter').click();
        }
    })
});
var path = '../';
var pageListUrl = path + 'contract/ContractPostionDetailList';
var pageUrl = path + 'contract/';

//添加弹窗
var addPanel = null;
// ---------------交互代码begin-----------------

//绑定列表List---begin----所有的操作都围绕列表展开，新增、更新其他比较独立 
var dataList=new Vue({
	el:"#contractPostionDetailList",
	data:{
        manCount:"",
        womenCount:"",
        sexs:"",
		pageInfo : {},
        list : {},
		//TODO 自定义条件查询---begin--------
        condition:{
            page:1,
            rows:customUtils.pageSize,
            items:[],
            all:false,
            startDate:"",
            overDate:"",
            equipmentCode:"",
            status:"",
            key:"",
            id:"",
            postionCode:"",
            shopCode:"",
            companyName:"",
            shopName:"",
            shopContacts:"",
            shopPhone:"",
            empno:"",
            address:"",
            createdBy:"",
            createdDate:"",
            updatedBy:"",
            updatedDate:"",
            sex:"1",
            earlyYouthAge:"",
            youthAge:"",
            adultAge:"",
            middleAge:"",
            oldAge:"",
            status:"",
        },
		//自定义条件查询---end--------
		selectIds:[],//多选
		showSuccess:false,//false不显示成功提示
		selectedIdx:-1,//保存操作行的索引
		isSearch:false,//init:页面初始化；search:点击查询；paging:点击翻页；changePageSize:改变页面显示条数
		selectedPageSize:customUtils.pageSize//修改页面数据显示条数
	},
	mounted: function () {
		//初始化页面数据
		this.getList('init');
	},
// 	// 在 `methods` 对象中定义方法,如果操作中函数的逻辑比较复杂，必须封装到dictType对象
	methods:{
        changeTime:function(elem){
            dataList.$data.condition[elem.split('-')[0]] = $("#"+elem).val();
            console.log(dataList.$data.condition);
        },
		//搜索、分页列表
		getList:function(eventSrc){
			var self=this;
			//改变页面显示条数
			if(eventSrc=="changePageSize"){
				if(this.pageInfo.pageSize != this.selectedPageSize){
					this.pageInfo.pageSize=this.selectedPageSize;
					$('#pagination').jqPaginator('destroy');
					eventSrc='init';//重新绘制控件
				}else{
					return;
				}
			}
			//初始化时无当前页数，后台有默认第1页，每页10条
			if(this.pageInfo!=undefined && this.pageInfo.pageNum!=undefined){
				self.condition["page"]=this.pageInfo.pageNum;
				self.condition["rows"]=this.pageInfo.pageSize;
			}
            var param = {};
			param["page"] = self.condition["page"];
			param["rows"] = self.condition["rows"];
            param["status"] = self.condition["status"];
            param["startDate"] = self.condition["startDate"];
            param["overDate"] = self.condition["overDate"];
            param["key"] = self.condition["key"];
            param["sex"] = self.condition["sex"];
            this.condition.items = [];
            console.log(param)
			//查询请求
			//发送请求,第一个参数http对象，第二个是url，第三个是参数，第四个是成功回调，第五个是请求失败回调
			customUtils.post(self,pageListUrl,param,function(response,isSuccess){
				//isSuccess代表此请求是否成功
				console.log(param);
				console.log(pageListUrl);
				if(isSuccess==false) {
                    dataList.pageInfo.pages = 0;
                    return;
                }
                dataList.list = response.body.list;
				dataList.pageInfo = response.body.pagination;
                dataList.sexs=response.body.sexs;
                dataList.manCount=response.body.manCount;
                dataList.womenCount=response.body.womenCount;
                var count='11';
                // if(response.body.sexs=='男'){
                //     count='11';
                // }
                // if(response.body.sexs=='女'){
                //     count='11';
                // }
                document.getElementById("manCount").rowSpan=count;
                //页面初始化、搜索时，才需要执行分页控件
				if(eventSrc=='init' || eventSrc=='search'){
                    customUtils.paging('#pagination',dataList.pageInfo.pages,customUtils.showPage,function(num){
                        //当前页码pageNum与将要翻页的页码num不相等才执行，否则为同一页
                        if(dataList.pageInfo.pageNum!=num){
                            dataList.pageInfo.pageNum=num;
                            dataList.getList('paging');
                        }
                    });
				}
            },function(response){
                console.log(response);
                dataList.pageInfo.pages=0;
            });
		}
	}
});
//绑定列表List---end----


